/**
 * 
 */
package com.totyu.BidDeposit.config;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import redis.clients.jedis.JedisSentinelPool;

/**
 * @author totyu
 */
@Configuration
@PropertySource("classpath:application.yml")
public class RedisConfig {

    @Value("${spring.redis.password}")
    private String password;

    @Value("${spring.redis.sentinel.master}")
    private String master;

    @Value("${spring.redis.sentinel.nodes}")
    private String nodes;

    @Bean
    public JedisSentinelPool jedisPoolFactory() {
        String[] nodess = (nodes != null && nodes.length() > 0) ? nodes.split(",") : null;

        Set<String> sentinels = new HashSet<String>();
        for (String node : nodess) {
            sentinels.add(node);
        }

        JedisSentinelPool jsentinelPool = new JedisSentinelPool(master, sentinels, password);

        return jsentinelPool;
    }
}
